package com.easyaccount.controller;

import com.easyaccount.commons.CommonResp;
import com.easyaccount.commons.TablePage;
import com.easyaccount.model.Dept;
import com.easyaccount.service.DeptService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @RequestMapping("all")
    public CommonResp all(){
        return deptService.list();
    }

    @RequestMapping("list")
    public TablePage list(TablePage tablePage){
        return deptService.searchByName(tablePage, null);
    }

    @RequestMapping("add")
    public CommonResp list(Dept dept){
        return deptService.save(dept);
    }

    @RequestMapping("update")
    public CommonResp update(Dept dept){
        return deptService.update(dept);
    }

    @RequestMapping("delete")
    public CommonResp delete(Dept dept){
        return deptService.delete(dept);
    }

    @RequestMapping("search")
    public TablePage search(TablePage tablePage,@RequestParam("deptName") String deptName){
        TablePage result = deptService.searchByName(tablePage, deptName);
        return result;
    }

}
